package com.nursebetty.server.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.nursebetty.server.common.UserProfile;
import com.nursebetty.server.dao.BloodPressureDao;
import com.nursebetty.server.model.BloodPressure;

public class BloodPressureDaoImpl implements BloodPressureDao {
	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public List<BloodPressure> getResults(UserProfile user) {
		String sql="select * from BLOOD_PRESURE_ENTRY where USR_ID = " + user.getId();
		List<BloodPressure> result = this.jdbcTemplate.query(sql, new BloodPressureMapper());
		return result;
	}

	public void saveBloodPressure(UserProfile user, BloodPressure bloodPressure) {
		String sql="insert into BLOOD_PRESURE_ENTRY(USR_ID,BLOOD_PRESURE_ENTRY,BLOOD_PRESURE_RESULT) values (?,?,?,?) ";
		jdbcTemplate.execute(sql);
	}

	public String saveResults(BloodPressure bloodPressure, UserProfile user,
			String Result) {
		// TODO Auto-generated method stub
		return null;
	}

	private static final class BloodPressureMapper implements RowMapper {

		public BloodPressure mapRow(ResultSet rs, int rowNum) throws SQLException {
			BloodPressure bp = new BloodPressure();
			bp.setBloodPressureValue(rs.getInt("BLOOD_PRESURE_RESULT"));
			return bp;
		}
	}

}
